WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
feature_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Forward declarations for node templates
22namespace wolf
23{
24class CaptureBase;
25class FactorBase;
26} // namespace wolf
27
28// Wolf includes
29#include "core/common/wolf.h"
31
32// std includes
33
34namespace wolf
35{
39class FeatureBase : public NodeBase, public std::enable_shared_from_this<FeatureBase>
40{
41 friend CaptureBase;
42 friend SensorBase;
43 friend FactorBase;
44
45 private:
46 CaptureBaseWPtr capture_ptr_;
47 FactorBasePtrList factor_list_;
48
49 static unsigned int feature_id_count_;
50
51 protected:
52 unsigned int feature_id_;
53 unsigned int track_id_;
54 unsigned int landmark_id_;
55 Eigen::VectorXd measurement_;
56 Eigen::MatrixXd measurement_covariance_;
58 Eigen::VectorXd expectation_;
59
60 public:
63 typedef enum
64 {
69
78 FeatureBase(const std::string& _type,
79 const Eigen::VectorXd& _measurement,
80 const Eigen::MatrixXd& _meas_uncertainty,
81 UncertaintyType _uncertainty_type = UNCERTAINTY_IS_COVARIANCE);
82
83 ~FeatureBase() override = default;
84
89 virtual void remove(bool viral_remove_parent_without_children = false);
90 bool hasChildren() const override
91 {
92 return not factor_list_.empty();
93 };
94
95 // properties
98 unsigned int id() const;
99
102 unsigned int trackId() const
103 {
104 return track_id_;
105 }
106
109 void setTrackId(unsigned int _tr_id)
110 {
111 track_id_ = _tr_id;
112 }
113
116 unsigned int landmarkId() const
117 {
118 return landmark_id_;
119 }
120
123 void setLandmarkId(unsigned int _lmk_id)
124 {
125 landmark_id_ = _lmk_id;
126 }
127
128 // values
133 double getMeasurement(unsigned int _ii) const;
134
137 const Eigen::VectorXd& getMeasurement() const;
138
139 private:
144 void setMeasurement(const Eigen::VectorXd& _meas);
145
148 void setMeasurementCovariance(const Eigen::MatrixXd& _meas_cov);
149
153 void setMeasurementInformation(const Eigen::MatrixXd& _meas_info);
154
155 public:
158 const Eigen::MatrixXd& getMeasurementCovariance() const;
159
162 Eigen::MatrixXd getMeasurementInformation() const;
163
166 const Eigen::MatrixXd& getMeasurementSquareRootInformationUpper() const;
167
170 const Eigen::VectorXd& getExpectation() const;
171
174 void setExpectation(const Eigen::VectorXd& expectation);
175
176 // wolf tree access
179 FrameBaseConstPtr getFrame() const;
180
183 FrameBasePtr getFrame();
184
187 CaptureBaseConstPtr getCapture() const;
188
191 CaptureBasePtr getCapture();
192
195 FactorBaseConstPtrList getFactorList() const;
196
199 FactorBasePtrList getFactorList();
200
203 void getFactorList(FactorBaseConstPtrList& _fac_list) const;
204
207 void getFactorList(FactorBasePtrList& _fac_list);
208
211 bool hasFactor(FactorBaseConstPtr _fac) const;
212
215 void link(CaptureBasePtr cap_ptr);
216
219 template <typename classType, typename... T>
220 static std::shared_ptr<classType> emplace(CaptureBasePtr _cpt_ptr, T&&... all);
221
224 virtual void printHeader(int depth, //
225 bool factored_by, //
226 bool metric, //
227 bool state_blocks,
228 std::ostream& stream,
229 std::string _tabs = "") const;
230
233 void print(int depth, //
234 bool factored_by, //
235 bool metric, //
236 bool state_blocks,
237 std::ostream& stream = std::cout,
238 std::string _tabs = "") const;
239
242 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
243
246 bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
247
248 private:
251 void setCapture(CaptureBasePtr _cap_ptr)
252 {
253 capture_ptr_ = _cap_ptr;
254 }
255
258 FactorBasePtr addFactor(FactorBasePtr _co_ptr);
259
262 void removeFactor(FactorBasePtr _co_ptr);
263};
264
265} // namespace wolf
266
267// IMPLEMENTATION
268
270
271namespace wolf
272{
273template <typename classType, typename... T>
274std::shared_ptr<classType> FeatureBase::emplace(CaptureBasePtr _cpt_ptr, T&&... all)
275{
276 std::shared_ptr<classType> ftr = std::make_shared<classType>(std::forward<T>(all)...);
277 ftr->link(_cpt_ptr);
278 return ftr;
279}
280
281inline FactorBaseConstPtrList FeatureBase::getFactorList() const
282{
283 FactorBaseConstPtrList list_const;
284 for (auto&& obj_ptr : factor_list_) list_const.push_back(obj_ptr);
285 return list_const;
286}
287
288inline FactorBasePtrList FeatureBase::getFactorList()
289{
290 return factor_list_;
291}
292
293inline unsigned int FeatureBase::id() const
294{
295 return feature_id_;
296}
297
298inline CaptureBaseConstPtr FeatureBase::getCapture() const
299{
300 return capture_ptr_.lock();
301}
302
303inline CaptureBasePtr FeatureBase::getCapture()
304{
305 return capture_ptr_.lock();
306}
307
308inline double FeatureBase::getMeasurement(unsigned int _ii) const
309{
310 return measurement_(_ii);
311}
312
313inline const Eigen::VectorXd& FeatureBase::getMeasurement() const
314{
315 return measurement_;
316}
317
318inline const Eigen::MatrixXd& FeatureBase::getMeasurementCovariance() const
319{
321}
322
323inline Eigen::MatrixXd FeatureBase::getMeasurementInformation() const
324{
326}
327
328inline const Eigen::MatrixXd& FeatureBase::getMeasurementSquareRootInformationUpper() const
329{
331}
332
333inline const Eigen::VectorXd& FeatureBase::getExpectation() const
334{
335 return expectation_;
336}
337
338inline void FeatureBase::setExpectation(const Eigen::VectorXd& expectation)
339{
340 expectation_ = expectation;
341}
342
343} // namespace wolf
Base class of captures: a sensor measurement taken at a time stamp, linked to a frame,...
Definition: capture_base.h:41
Log of a consistency check: whether it is consistent and the explanation of the inconsistencies.
Definition: check_log.h:30
Base class of factors: a constraint between state blocks of one or more nodes, given a measurement an...
Definition: factor_base.h:73
Base class of features: a measurement with its uncertainty, extracted from a capture,...
Definition: feature_base.h:40
bool hasFactor(FactorBaseConstPtr _fac) const
Returns whether the factor belongs to the feature.
Definition: feature_base.cpp:97
unsigned int feature_id_
Feature id, unique among features.
Definition: feature_base.h:52
FeatureBase(const std::string &_type, const Eigen::VectorXd &_measurement, const Eigen::MatrixXd &_meas_uncertainty, UncertaintyType _uncertainty_type=UNCERTAINTY_IS_COVARIANCE)
Constructor from the measurement and its uncertainty.
Definition: feature_base.cpp:28
CaptureBaseConstPtr getCapture() const
Returns the capture the feature belongs to (nullptr if none)
Definition: feature_base.h:298
Eigen::VectorXd expectation_
Expected measurement.
Definition: feature_base.h:58
Eigen::MatrixXd measurement_covariance_
Measurement covariance matrix.
Definition: feature_base.h:56
Eigen::MatrixXd measurement_sqrt_information_upper_
Upper square root of the information matrix.
Definition: feature_base.h:57
Eigen::MatrixXd getMeasurementInformation() const
Returns the measurement information matrix.
Definition: feature_base.h:323
void link(CaptureBasePtr cap_ptr)
Links the feature to a capture.
Definition: feature_base.cpp:152
const Eigen::MatrixXd & getMeasurementSquareRootInformationUpper() const
Returns the upper triangular square root of the measurement information matrix.
Definition: feature_base.h:328
void setLandmarkId(unsigned int _lmk_id)
Sets the id of the landmark.
Definition: feature_base.h:123
static std::shared_ptr< classType > emplace(CaptureBasePtr _cpt_ptr, T &&... all)
Creates a feature of class classType and links it to the capture.
Definition: feature_base.h:274
bool hasChildren() const override
Returns whether the node has children in the Wolf tree.
Definition: feature_base.h:90
~FeatureBase() override=default
UncertaintyType
Type of the measurement uncertainty passed to the constructor.
Definition: feature_base.h:64
@ UNCERTAINTY_IS_STDDEV
Standard deviations (not implemented)
Definition: feature_base.h:67
@ UNCERTAINTY_IS_INFO
Information matrix.
Definition: feature_base.h:66
@ UNCERTAINTY_IS_COVARIANCE
Covariance matrix.
Definition: feature_base.h:65
const Eigen::VectorXd & getMeasurement() const
Returns the measurement vector.
Definition: feature_base.h:313
unsigned int track_id_
ID of the feature track.
Definition: feature_base.h:53
const Eigen::VectorXd & getExpectation() const
Returns the expected measurement.
Definition: feature_base.h:333
FactorBaseConstPtrList getFactorList() const
Returns the factors of the feature.
Definition: feature_base.h:281
Eigen::VectorXd measurement_
Measurement vector.
Definition: feature_base.h:55
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Prints the information of this node (not of its children)
Definition: feature_base.cpp:168
void setExpectation(const Eigen::VectorXd &expectation)
Sets the expected measurement.
Definition: feature_base.h:338
unsigned int landmark_id_
ID of the landmark.
Definition: feature_base.h:54
FrameBaseConstPtr getFrame() const
Returns the frame of the capture the feature belongs to.
Definition: feature_base.cpp:112
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node (not of its children)
Definition: feature_base.cpp:195
void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Prints this node and, depending on the depth, its children.
Definition: feature_base.cpp:182
unsigned int id() const
Returns the feature id.
Definition: feature_base.h:293
void setTrackId(unsigned int _tr_id)
Sets the id of the feature track.
Definition: feature_base.h:109
unsigned int trackId() const
Returns the id of the feature track.
Definition: feature_base.h:102
unsigned int landmarkId() const
Returns the id of the landmark.
Definition: feature_base.h:116
bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Checks the consistency of this node and its children, composing the log.
Definition: feature_base.cpp:233
const Eigen::MatrixXd & getMeasurementCovariance() const
Returns the measurement covariance.
Definition: feature_base.h:318
virtual void remove(bool viral_remove_parent_without_children=false)
Removes the feature and its factors.
Definition: feature_base.cpp:56
Base class for Nodes.
Definition: node_base.h:73
Base class of sensors: their state blocks (extrinsics and intrinsics, static or dynamic),...
Definition: sensor_base.h:128
Definition: capture_base.h:23